package com.example.wanjialei.service.serviceimpl;

import com.example.wanjialei.mapper.StockMapper;
import com.example.wanjialei.mapper.SummaryMapper;
import com.example.wanjialei.pojo.Stock;
import com.example.wanjialei.pojo.Summary;
import com.example.wanjialei.service.StockService;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service
public class StockImpl implements StockService {

    @Resource
    private StockMapper stockMapper;

    @Override
    public Map<String, Object> getStockInfo(Stock stock) {
        Map<String,Object> map = new HashMap<>();
        // 进行分页设置：给分页框架的方法中传入当前页面数据和每页显示的件数
        PageHelper.startPage(stock.getPage(), stock.getRows());
        List <Stock> list = stockMapper.selectAll(stock);
        // 将查询的结果进行分页
        PageInfo <Stock> pageInfo = new PageInfo <>(list);
        if (list.size() >= 1){
            map.put("flag",true);
            map.put("message","数据查询成功");
            // 获取分页后的数据
            map.put("rows", pageInfo.getList());
            // 获取总件数
            map.put("total", pageInfo.getTotal());
        }else{
            map.put("flag",false);
            map.put("message","数据查询失败");
            map.put("rows", pageInfo.getList());
            map.put("total", pageInfo.getTotal());
        }
        return map;
    }

    @Override
    public Map<String, Object> approvedBysno(Stock stock) {
        Map<String,Object> map = new HashMap<>();
        Integer count = stockMapper.approvedBysno(stock);
        if(count == 1){
            map.put("flag", true);
            map.put("message", "审核通过成功！");
            map.put("count", count);
        }else{
            map.put("flag", true);
            map.put("message", "审核通过失败！");
            map.put("count", count);
        }
        return map;
    }

    @Override
    public Map<String, Object> rejectedBysno(Stock stock) {
        Map<String,Object> map = new HashMap<>();
        Integer count = stockMapper.rejectedBysno(stock);
        if(count == 1){
            map.put("flag", true);
            map.put("message", "驳回成功！");
            map.put("count", count);
        }else{
            map.put("flag", true);
            map.put("message", "驳回失败！");
            map.put("count", count);
        }
        return map;
    }

    @Override
    public Map<String, Object> recheckBysno(Stock stock) {
        Map<String,Object> map = new HashMap<>();
        Integer count = stockMapper.recheckBysno(stock);
        if(count == 1){
            map.put("flag", true);
            map.put("message", "复核通过成功！");
            map.put("count", count);
        }else{
            map.put("flag", true);
            map.put("message", "复核通过失败！");
            map.put("count", count);
        }
        return map;
    }

    @Override
    public Map<String, Object> huizongBysno(Stock stock) {
        Map<String,Object> map = new HashMap<>();
        Integer count = stockMapper.huizongBysno(stock);
        if(count == 1){
            map.put("flag", true);
            map.put("message", "汇总成功！");
            map.put("count", count);
        }else{
            map.put("flag", true);
            map.put("message", "汇总失败！");
            map.put("count", count);
        }
        return map;
    }

    @Override
    public List getStockInfo2() {
        List list = new ArrayList();
        list = stockMapper.selectAll2();
        return list;
    }
}
